#include "ThreadPool.hpp"
#include "Task.hpp"
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <sys/types.h>
#include <unistd.h>
#include "log.hpp"


int main(){

    //logMessage(NORMAL, "%d-%s-%d\n",1,"你好",2);

#if 1

    srand((unsigned long)time(nullptr) ^ getpid());

    std::cout << "Hello Thread Pool " << std::endl;

    // ThreadPool<int>* tp = new ThreadPool<int>(5);
    ThreadPool<Task>* tp = new ThreadPool<Task>();

    // 注意：此处创建的是子线程！
    tp->run();

    // tp->joins();

    // 此处：为主线程任务
    while(true){
        // 主线程生产任务：只做任务是需要花费时间的！
        int x = rand()%100 + 1;
        usleep(4354);
        int y = rand()%30 + 1;

        Task t(x, y, [](int x, int y)->int{
            return x+y;
        });
        // std::cout << "制作任务完成：" << x << " + " << y << " =?" << std::endl;
        logMessage(DEBUG, " 制作任务完成：%d + %d = ？",x,y);
        // 推送任务到线程池中！
        tp->pushTask(t);
        usleep(rand()%532164);

    }
    
#endif
    return 0;
}